﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PwdMgrUI
{
    /// <summary>
    /// Interaction logic for Navigation.xaml
    /// </summary>
    public partial class Navigation : UserControl
    {
        public Navigation()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Navigation_Loaded);
        }

        void Navigation_Loaded(object sender, RoutedEventArgs e)
        {
            this.btn_Add.Click += new RoutedEventHandler(Btn_Add_Click);
            this.btn_Search.Click += new RoutedEventHandler(Btn_Search_Click);

            SetContent(new Search());
        }

        void Btn_Search_Click(object sender, RoutedEventArgs e)
        {
            UIElement ele = GetContent();

            if (ele == null || ele.GetType() != typeof(Search))
            {
                SetContent(new Search());
            }
        }

        void Btn_Add_Click(object sender, RoutedEventArgs e)
        {
            UIElement ele = GetContent();

            if (ele == null || ele.GetType() != typeof(AddSensitiveInfo))
            {
                AddSensitiveInfo editInfo = new AddSensitiveInfo();
                editInfo.AddCompleted += new Action(EditCompleted);
                SetContent(editInfo);
            }
        }

        void EditCompleted()
        {
            SetContent(new Search());
        }

        private void SetContent(UIElement ele)
        {
            this.grid_Content.Children.Clear();
            this.grid_Content.Children.Add(ele);
        }

        private UIElement GetContent()
        {
            return this.grid_Content.Children[0];
        }
    }
}
